/*
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */
package sg.edu.nus.iss.vmcs.customer;

import sg.edu.nus.iss.vmcs.util.VMCSException;

/**
 * This control object manages the giving of change to the Customer.
 * @author Team SE16T5E
 * @version 1.0 2008-10-01
 * @editedby A0119952X - Singleton Design Pattern
 */
public class ChangeGiver {
	private Facade facade = Facade.getInstance();

    private static ChangeGiver instance;
    private ChangeGiver() {
    }

    public static ChangeGiver getInstance() {
        if (instance == null) {
            instance = new ChangeGiver();
        }
        return instance;
    }

	/**
	 * This method is used to reset the Refund/ Change Tray display on the
	 * Customer Panel.
	 */
	public void resetChange(){
		facade.resetChange();
	}
	
	/**
	 * This method manages the issuing of change to the Customer.
	 * @param changeRequired
	 * @return return TRUE if give change use case success, otherwise, return FALSE.
	 */
	public boolean giveChange(int changeRequired){
		if(changeRequired==0)
			return true;
		try{
			facade.giveChange(changeRequired);
		}
		catch(VMCSException ex){
			TransactionController.getInstance().terminateFault();
			return false;
		}
		return true;
	}
	
	/**
	 * This method is used to display the appropriate message on the No Change
	 * Available Display depending on the current change availability.
	 */
	public void displayChangeStatus(){
		facade.displayChangeStatus();
	}
}//End of class ChangeGiver